#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
/*
求 a 乘 b 对 p 取模的值。

*/

LL a, b, p;

LL qmi(LL a, LL b, LL p){
    LL res = 0;
    LL s = a;
    while(b){
        if(b & 1) res = (res + s) % p;

        s = (s % p) * 2 % p;
        b >>= 1;
    }

    return res;
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> a >> b >> p;
    cout << qmi(a, b, p);


    return 0;
}